#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <string>
using namespace std;

class Request
{
public:
    Request(int start, int end, string name)
        : _start(start), _end(end), _name(name)
    {
    }

public:
    int _start; // 起始
    int _end;
    string _name;
};

class Response
{
public:
    Response(int result, string name)
        : _result(result), _name(name)
    {
    }

public:
    string _name;
    int _result;
};

void *sumCount(void *Rq)
{
    Request *range = (Request *)Rq;
    int result = 0;
    for (int i = range->_end; i >= range->_start; i--)
    {
        result += i;
    }
    Response *ret = new Response(result,range->_name);
    return (void *)ret;
}

void *printThreadInfo(void *arg)
{
    pid_t tid = getpid();
    while(true)
    {
        cout<< "Thread ID: " << tid << endl;
        sleep(1);
    }
    return nullptr;
}

int main()
{

    // pthread_t tid;
    // Request *rq = new Request(1, 100, "Thread 1");
    // // pthread_create(&tid, nullptr, sumCount, rq);
    // void *ret;
    // pthread_join(tid, &ret);
    // Response* rp = (Response*)ret;
    // cout<<rp->_name<<":"<<rp->_result<<endl;
    // delete rq;
    // delete rp;

    pthread_t tid;
    pthread_create(&tid, nullptr, printThreadInfo, nullptr);
    pid_t pid = getpid();
    while(true)
    {
        cout<< "Main Thread ID: " << pid << endl;
        sleep(1);
    }
    pthread_join(tid, nullptr);
    return 0;
}